package com.fypg.module.blooddonation.api.client.enums;

import lombok.Getter;

@Getter
public enum BloodDonationType {

    WHOLE_BLOOD("0", "全血"),
    APHERESIS("1", "机采");

    private final String code;
    private final String desc;

    BloodDonationType(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据 code 获取描述
     */
    public static String getDescByCode(String code) {
        for (BloodDonationType type : values()) {
            if (type.code.equals(code)) {
                return type.desc;
            }
        }
        return null;
    }

    /**
     * 校验 code 是否有效
     */
    public static boolean isValid(String code) {
        for (BloodDonationType type : values()) {
            if (type.code.equals(code)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据 code 获取枚举
     */
    public static BloodDonationType fromCode(String code) {
        for (BloodDonationType type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        return null;
    }
}
